
import { Feature } from "../../models";

import * as fromFeatureAction from '../actions/feature.action';


export interface FeatureState {
    deselected: Feature,
    selected: Feature
}

export const initialFeatureState: FeatureState = {
    deselected: null,
    selected: null
};

export function featureReducer(
    state: FeatureState = initialFeatureState,
    action: fromFeatureAction.FeatureAction
): FeatureState {
    switch(action.type) {
        case fromFeatureAction.FeatureActionTypes.FEATURE_SELECTED: {
            return {
                ...state,
                deselected: state.selected,
                selected: action.payload
            }
        }
        default: {
            return state;
        }
    }
}